<script setup>
import { queryProvinces, queryCities, queryWeather } from "@/api/juhe/weather";
import { queryAirQuality, queryLifeIndex, queryWeatherForecast24,queryRealtime } from "@/api/moji/aliweather";
import { onMounted, ref } from "vue";

const key = '203adfac2e322343428c1735e82d10dc'

// onMounted(() => {
//   let city = '上海';
//   city = encodeURI(city)
//   // 从表逻辑 -- Over
//   queryWeather({city: city}).then(response => {    
//     console.log(response)
//   });
// });
const weatherInto = ref('')

// ---------- 墨迹天气服务 ----------
const GetAirQuality = (cityId) => {
  queryAirQuality({cityId: cityId}).then(response => {    
    console.log(response)
    weatherInto.value = response
  });
}

const GetLifeIndex = (cityId) => {
  queryLifeIndex({cityId: cityId}).then(response => {    
    console.log(response)
    weatherInto.value = response
  });
}

const GetWeatherForecast24 = (cityId) => {
  queryWeatherForecast24({cityId: cityId}).then(response => {    
    console.log(response)
    weatherInto.value = response
  });
}

const GetRealtimeWeather = (cityId) => {
  queryRealtime({cityId}).then(response => {    
    console.log(response)
    weatherInto.value = response
  });
}

// -------------------- 聚合数据接口 ----------
const GetProvinces = () => {
  queryProvinces({key: key}).then(response => {    
    console.log(response)
    weatherInto.value = response
  });
}

const GetCitesByProvince = (provinceId) => {
  queryCities({key: key, province_id: provinceId}).then(response => {    
    console.log(response)
    weatherInto.value = response
  });
}

const GetCityWeather = (cityId, weatherDate ) => {
  queryWeather({city_id: cityId, weather_date: weatherDate, key: key}).then(response => {    
    console.log(response)
    weatherInto.value = response
  });
}
</script>

<template>
  <header>
    <img alt="Vue logo" class="logo" src="@/assets/ch09/logo1.png" width="125" height="125" />
  </header>

  <main>
    <!-- <TheWelcome /> -->
    <h1 class="ml-4 mb-4">墨迹天气API测试</h1>
    <el-button class="ml-4 mb-4" @click="GetAirQuality('10')">获取空气质量</el-button><br/>
    <el-button class="ml-4 mb-4" @click="GetLifeIndex('2')">城市生活指数查询</el-button><br/>
    <el-button class="ml-4 mb-4" @click="GetWeatherForecast24('2')">获取24小时天气预报</el-button><br/>
    <el-button class="ml-4 mb-4" @click="GetRealtimeWeather('2')">获取实时天气</el-button><br/>

    <br/>
    <h1 class="ml-4 mb-4">聚合天气API测试</h1>
    <el-button class="ml-4 mb-4" @click="GetProvinces">获取省份</el-button><br/>
    <el-button class="ml-4 mb-4" @click="GetCitesByProvince('1')">根据省份获取支持的城市列表</el-button><br/>
    <el-button class="ml-4 mb-4" @click="GetCityWeather('70', '2024-10-01')">获取城市天气</el-button>
    <br/>
    <hr/>
    <h1 class="ml-4 mb-4">API结果</h1>
    <p>{{weatherInto}}</p>
  </main>
</template>

<style scoped>
header {
  line-height: 1.5;
}

.logo {
  display: block;
  margin: 0 auto 2rem;
}

@media (min-width: 1024px) {
  header {
    display: flex;
    place-items: center;
    padding-right: calc(var(--section-gap) / 2);
  }

  .logo {
    margin: 0 2rem 0 0;
  }

  header .wrapper {
    display: flex;
    place-items: flex-start;
    flex-wrap: wrap;
  }
}
</style>

